package rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import SQL.scan.Scan;

public class RemoteResultSetDB extends UnicastRemoteObject implements RemoteResultSet {
	public ArrayList < String > result = null ;
	int current = -1 ; 
	
	public RemoteResultSetDB ( ArrayList < String > result ) throws RemoteException {
		this.result = result ; 
	}

	public void close() throws RemoteException {
	}

	public int getInt(String fldname) throws RemoteException {
		return 0;
	}

	@Override
	public int getInt(int index) throws RemoteException {
		return 0;
	}

	@Override
	public RemoteMetaData getMetaData() throws RemoteException {
		return null;
	}

	@Override
	public String getString(String fldname) throws RemoteException {
		if ( current < 0 || current >= result.size()) throw new RemoteException ( "no more results") ;
		if ( fldname.equalsIgnoreCase( "TABLE_NAME") ||  fldname.equalsIgnoreCase( "COLUMN_NAME" ) ) {
			String str = result.get( current ) ; 
			str = str.substring( str.indexOf( '.' ) + 1 ) ; 
			return str ; 
		}
		else if ( fldname.equalsIgnoreCase( "INDEX_NAME" ) ) return "PRIMARY KEY" ;  
		else return "" ;
	}

	@Override
	public String getString(int index) throws RemoteException {
		return null;
	}

	@Override
	public boolean next() throws RemoteException {
		++ current; 
		if (current < result.size()) return true ; 
		else return false;
	}

	@Override
	public Scan getScan() throws RemoteException {
		// TODO Auto-generated method stub
		return null;
	}

}
